package com.example.lastwork.controller;

import com.example.lastwork.common.controller.LogicController;
import com.example.lastwork.dao.OrdersDao;
import com.example.lastwork.dto.RestDTO;
import com.example.lastwork.entity.LineItem;
import com.example.lastwork.entity.Orders;
import com.example.lastwork.service.OrdersService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "订单服务接口")
@RestController
@RequestMapping("/OrdersController")
public class OrdersController extends LogicController<OrdersService, OrdersDao, Orders, Long> {
    public OrdersController(@Autowired OrdersService service){
        super(service);
    }

    @ApiOperation("向订单中添加商品")
    @RequestMapping(value = "/addLineItem",method = RequestMethod.POST)
    public RestDTO<LineItem> addLineItem(@ApiParam("订单编号") Long ordersId, @ApiParam("商品名称") String lineItemName){
        return RestDTO.success(getService().addLineItem(ordersId, lineItemName));
    }

    @ApiOperation("移除订单中的商品")
    @RequestMapping(value = "/minusLineItem",method = RequestMethod.POST)
    public RestDTO<LineItem> minusLineItem(@ApiParam("订单编号") Long ordersId, @ApiParam("商品名称") String lineItemName){
        return RestDTO.success(getService().minusLineItem(ordersId, lineItemName));
    }

    @ApiOperation("更新订单的总价")
    @RequestMapping(value = "/updateTotalPrice",method = RequestMethod.POST)
    public RestDTO<Integer> updateTotalPrice(@ApiParam("订单编号") Long ordersId, @ApiParam("订单总价") Double total){
        return RestDTO.success(getService().updateTotalPrice(ordersId, total));
    }
}
